$(function() {
    //添加账号 暂时不予调用
    var myclick = $('#my_submit');
    var tables = $('#teb_lsit');
    var my_fen = $('#my_fen');
    var fen_list = $('#fen_list');
    var my_shen = $('#my_shen');
    myclick.click(function () {
        var add_list = $('<tr><th><div class="formControls col-xs-8 col-sm-9"><input type="text" class="input-text radius"  name="username"   placeholder="请输入总账号"> </div> <label><input name="" type="reset" class="btn radius size-S c-blue" value="&nbsp;添&nbsp;&nbsp;加&nbsp;"></label> </th> <th> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text radius"  name="username"   placeholder="请输入分账号"> </div> <label><input name="" type="reset" class="btn radius size-S c-blue" value="&nbsp;添&nbsp;&nbsp;加&nbsp;"></label> </th> <th> <div class="formControls col-xs-8 col-sm-9"> <input type="text" class="input-text radius"  name="username"   placeholder="请输入审批账号"> </div> <label><input name="" type="reset" class="btn radius size-S c-blue" value="&nbsp;添&nbsp;&nbsp;加&nbsp;"></label></th></tr>');
        add_list.appendTo(tables);
    })
    my_fen.click(function () {
        var trtd = $('<tr><th></th><th><div class="formControls col-xs-8 col-sm-9"><input type="text" class="input-text radius"  name="username"   placeholder="请输入分账号"></div><label><input name="" type="reset"class="btn radius size-S c-blue" value="&nbsp;添&nbsp;&nbsp;加&nbsp;"></label></th><th></th></tr>');
        trtd.appendTo(tables);
    })
    my_shen.click(function () {
        var trtd = $('<tr><th></th><th></th><th><div class="formControls col-xs-8 col-sm-9"><input type="text" class="input-text radius"  name="username"   placeholder="请输入审批账号"></div><label><input name="" type="reset"class="btn radius size-S c-blue" value="&nbsp;添&nbsp;&nbsp;加&nbsp;"></label></th></tr>');
        trtd.appendTo(tables);
    })
});
//商品池初始化
function commoditypool() {
    $("#category_right").html("<img style='margin-top: 92px;margin-left: 40px;' width=\"40\" src=\"../../img/f096f4ca2bfdd4ab03d0b040f959ebef.gif\">")
    $("#category_lsit").html("<img style='margin-top: 92px;margin-left: 40px;' width=\"40\" src=\"../../img/f096f4ca2bfdd4ab03d0b040f959ebef.gif\">")
    var customerCode =getQueryString('id');
    var user_data = {
        customerCode:customerCode
    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if(data.errorCode=="0"){
            var content=data.list;
            var optionstring = ""
            for (var  i= 0; i < content.off.length; i++) {
                if(content.off[i].category_name==''){
                    content.off[i].category_name='暂无名字返回'
                }
                // optionstring += '<li class="list_item" style="line-height: 1.5"><input type="checkbox" class="checkBox" value="' + content.off[i].category_id + '" name="checkboxName" txt="' +  content.off[i].category_name  + '"><span class="checkout_val">' + content.off[i].category_name + '</span></li>';
                optionstring += '<li class="list_item" style="line-height: 1.5"><span class="checkout_val">' + content.off[i].category_name + '</span></li>';
            }
            $("#category_right").html(optionstring)
            var optionstrings = ""
            for (var  i= 0; i < content.on.length; i++) {
                if(content.on[i].category_name==''){
                    content.on[i].category_name='暂无名字返回'
                }
                // optionstrings += '<li class="list_item" style="line-height: 1.5"><input type="checkbox" class="checkBox" value="' + content.on[i].category_id + '" name="checkboxName" txt="' +  content.on[i].category_name  + '"><span class="checkout_val">' + content.on[i].category_name + '</span></li>';
                optionstrings += '<li class="list_item" style="line-height: 1.5"><span class="checkout_val">' + content.on[i].category_name + '</span></li>';
            }
            $("#category_lsit").html(optionstrings)
            // if(content.off.length==0){
            //     var optionstringser=' <img width="110" src="../../img/f096f4ca2bfdd4ab03d0b040f959ebef.gif">'
            //     $("#category_right").html(optionstringser)
            // }
            if(content.off==''&& content.on==''){
                $('#tishui').text('暂无数据')
                $(".public_ico").addClass('prohibit')
            }
            Index.init();
        }
    }
    web.doAjax(root.inter.getAllCategoryDiscount,'post',user_data, succCallBack);
}
//商品池操作
var Index = {
    init:function(){
        this.higHlight($('.dataList input'))
    },
    getCheckVal:function(type, event){
        var me=this;
        // 0从左到右   1从右到左
        var inputs = event.find('input[type="checkbox"]');
        me.obj = {
            left: [],
            right: []
        };
        me.checkoutStr = ''
        for (var i=0;i<inputs.length;i++) {
            if (inputs[i].checked) {
                // 获取选中input的文本内容
                var txt = inputs[i].getAttribute('txt');
                type == 0 ? me.obj.left.push(inputs[i].value):me.obj.right.push(inputs[i].value);
                // 清空内容
                inputs[i].parentElement.remove();
                // 添加内容
                me.checkoutStr += '<li class="list_item"><input type="checkbox" class="checkBox" value="' + inputs[i].value + '" name="checkboxName" txt="'+ txt +'"><span class="checkout_val">'+ txt +'</span></li>'
            }
        }
    },
    checkoutList:function(type){
        var me=this;
        var event1 = type == 0 ? $('.yesList'):$('.noList');
        var event2 = type == 0 ? $('.noList'):$('.yesList');
        // 获取选中的值，把选中的内容追加到对应的位置
        event2.append(me.checkoutStr);
        // 动态追加绑定事件
        me.higHlight($('.dataList input'));
    },
    higHlight:function(el){
        var me = this
        var checkBox = el;
        checkBox.click(function(){
            var types=$(this).parents('ul').data('types');
            // 0从左到右   1从右到左
            var event1 = types == 0 ? $('.yesList'):$('.noList');
            var event2 = types == 0 ? $('.noList'):$('.yesList');
            var event3 = types == 0 ? $('.yes_arrow'):$('.no_arrow');
            var inputs = event2.find('input[type="checkbox"]');
            var inputs2 = event1.find('input[type="checkbox"]');
            // 判断是复选框是否有选中的
            var checkedLen = 0;
            for (var i=0;i<inputs2.length;i++) {
                if (inputs2[i].checked) {
                    checkedLen ++;
                }
            }
            if (checkedLen<1) {
                $('.buleArrow').removeClass('buleArrow');
                me.bgUrl(0, types, event3);
                $('.dataList input').attr("disabled",false);
                return;
            }
            // 对应位置的复选框不能选择
            inputs.attr("disabled",true);
            // 添加高亮
            event3.addClass('buleArrow').siblings().removeClass('buleArrow');
            me.bgUrl(1, types, $('.buleArrow'));
        })
    },
    bindEvent:function(type){
        var me = this
        //  var type=event.data('type');
        var event1 = type == 0 ? $('.yesList'):$('.noList');
        var event2 = type == 0 ? $('.noList'):$('.yesList');
        var event3 = type == 0 ? $('.yes_arrow'):$('.no_arrow');
        var inputs = event2.find('input[type="checkbox"]');
        // 清除掉div原本绑定的事件
        event3.off();
        // me.getCheckVal(type, event1);
        var txtStr = type==0?'你确定要下架吗':'你确定上要架吗'
        layer.confirm(txtStr,function(index){
            // 获取值
            me.getCheckVal(type,event1)
            var user_data_pain = {
                customerCode:getQueryString('id'),
            }
            var user_data_pains = {
                customerCode:getQueryString('id'),
                contractId:sessionStorage.getItem("bel_contract_id"),
                isAllOpen:'1'

            }
            var categoryId = type==0 ? me.obj.left:me.obj.right
            user_data_pain.categoryIds= categoryId.join(",")
            user_data_pains.categoryIds= categoryId.join(",")
            var succCallBack_pin = function (data, status, response) {
                // 赋值
                me.checkoutList(type);
                // 清除高亮
                event3.removeClass('buleArrow');
                me.bgUrl(0, type, event3);
                // 清除复选框不能点击事件
                inputs.attr("disabled",false);
                if(data.errorCode==0){
                    layer.msg('操作成功!',{icon: 1,time:2000});
                    $('#daku').val('1');
                }
            }
            if (type==0) {
                // console.log('ha'+user_data_pain)
                //上架
                web.doAjax(root.inter.deleteCategory, 'post', user_data_pain, succCallBack_pin);
            } else {
                //下架
                web.doAjax(root.inter.addCategory, 'post', user_data_pains, succCallBack_pin);
            }
        });
    },
    bgUrl:function(types,type, event){
        // types  表示是灰色箭头[0]还是蓝色[1]
        var bgUrl = '';
        if (types == 1) {
            bgUrl = type == 0?'url(../../img/oods_r.png) no-repeat center':'url(../../img/oods_r_f.png) no-repeat center'
        } else {
            bgUrl = type == 0?'url(../../img/oods_l_f.png) no-repeat center':'url(../../img/oods_l.png) no-repeat center'
        }
        event.css({
            "background": bgUrl
        })
    }
};
setTimeout(function () {
    discounts()// 默认全部上架
},200);
//判断商品池上方全部
function discounts() {
    var fanx = $("#whole_data").val()
    // $("#daku").change(function(event) {
    //     var fanx = $(this).find("option:selected");
    if(fanx==0){
        // console.log(fanx.val()+'选择')
        var user_data_pain = {
            customerCode:getQueryString('id'),
            isAllOpen:0,
            contractId:sessionStorage.getItem("bel_contract_id"),
        }
        var succCallBack_pin = function (data, status, response) {
            if( data.errorCode==0){
                commoditypool()//点击全部加载
            }
        }
        web.doAjax(root.inter.addCategory, 'post', user_data_pain, succCallBack_pin);
        return false

    }else{
        // alert(fanx.val())
    }
    // });
}
/*$("#zomg-add").validate({
    rules: {
        zong: {
            required: true,
            maxlength:18,
            minlength:5,
        },
    },
    submitHandler:function(form){
        number_guan(1)
    }
});*/
//添加分账号
/*$("#fen-add").validate({
    rules: {
        fen: {
            required: true,
            maxlength:18,
            minlength:5,
        },
    },
    submitHandler:function( rules){
        number_guan(2 ,rules)
    }
})*/
//添加审批账号
/*$("#shen-add").validate({
    rules: {
        shen: {
            required: true,
            maxlength:18,
            minlength:5,
        },
    },
    submitHandler:function(form){
        number_guan(3)
    }
})*/
//调取添加账号
function number_guan(type,value) {
    var Indexes= type - 1
    var account = $(".zang_int").eq(Indexes).val();
    var user_data = {
        accountType: type,
        loginAccount: account,
        belongCustomerCode:getQueryString('id'),
        belongCustomerId:getQueryString('customerId')
    }
    var succCallBack = function (data, status, response) {
        if (data.errorCode == "1") {
            $.Huimodalalert('添加成功', 2000)
            setTimeout(function(){
                account = $(".zang_int").val("");
                location.replace(location.href)
            },1000)
        } else {
            $.Huimodalalert(data.errorMessage, 2000)
        }
    };
    return web.doAjax(root.inter.addCustomerAccount, 'post', user_data, succCallBack);
}
//账号
var fen_lsitid=""
var shen_listid=""
var zong_lsitid=""
function myfFunction(){
    var customerCode = getQueryString('id');
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/amembership/findAccountByCustomerCode.jhtml',
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            customerCode: customerCode,
            loginAccount: $("#zong_lsit").val(),
        },
        success: function (data) {
            console.log(data)
            var jsonObj =data.account;
            if(jsonObj==""){
                $("#tudfan1").html("<li>无数据</li> ");
            }else {
                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<li onclick='addCodeFun("+ jsonObj[i].member_id+ ",\""+jsonObj[i].login_account+ "\")'>"+jsonObj[i].login_account+ "</li>";
                }
                $("#tudfan1").html(optionstring);
            }
        }
    });
}
//运营经理获取光标
$("#zong_lsit").focus(function () {
    $("#tudfan1").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tudfan1").length == 0 && $(e.target).closest("#zong_lsit").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tudfan1").hide()
    }
})
function addCodeFun(id,brand_name) {
    console.log("11111111111111111122222222ffffffffffff")
    console.log(id)
    zong_lsitid=id
   /* sessionStorage.setItem("zong_lsitid",id)*/
    $("#tudfan1").hide();
    $("#zong_lsit").val(brand_name)
}


function myfFunction2(){
    var customerCode = getQueryString('id');
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/amembership/findAccountByCustomerCode.jhtml',
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            customerCode: customerCode,
            loginAccount: $("#fen_lsit").val(),
        },
        success: function (data) {
            var jsonObj =data.account;
            if(jsonObj==""){
                $("#tudfan2").html("<li>无数据</li> ");
            }else {
                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<li onclick='addCodeFun2("+ jsonObj[i].member_id+ ",\""+jsonObj[i].login_account+ "\")'>"+jsonObj[i].login_account+ "</li>";
                }
                $("#tudfan2").html(optionstring);
            }
        }
    });
}
//运营经理获取光标
$("#fen_lsit").focus(function () {
    $("#tudfan2").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tudfan2").length == 0 && $(e.target).closest("#fen_lsit").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tudfan2").hide()
    }
})
function addCodeFun2(id,brand_name) {
   /* sessionStorage.setItem("fen_lsitid",id)*/
    fen_lsitid=id
    $("#tudfan2").hide();
    $("#fen_lsit").val(brand_name)
}
function myfFunction3(){
    var customerCode = getQueryString('id');
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/amembership/findAccountByCustomerCode.jhtml',
        cache: false,  //禁用缓存
        type: "POST",
        data: {
            customerCode: customerCode,
            loginAccount: $("#shen_list").val(),
        },
        success: function (data) {
            var jsonObj =data.account;
            if(jsonObj==""){
                $("#tudfan3").html("<li>无数据</li> ");
            }else {
                var optionstring = "";
                for (var  i= 0; i < jsonObj.length; i++) {
                    optionstring += "<li onclick='addCodeFun3("+ jsonObj[i].member_id+ ",\""+jsonObj[i].login_account+ "\")'>"+jsonObj[i].login_account+ "</li>";
                }
                $("#tudfan3").html(optionstring);
            }
        }
    });
}
//运营经理获取光标
$("#shen_list").focus(function () {
    $("#tudfan3").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tudfan3").length == 0 && $(e.target).closest("#shen_list").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tudfan3").hide()
    }
})
function addCodeFun3(id,brand_name) {
    shen_listid=id
    /*sessionStorage.setItem("shen_listid",id)*/
    $("#tudfan3").hide();
    $("#shen_list").val(brand_name)
}



//初始化 获取账号建立关系
// web.science=(function(){
$('#jianli').bind('click',function() {
    console.log(fen_lsitid)
    console.log(shen_listid)
    console.log(zong_lsitid)
    var zong_lsit = $('#zong_lsit').val(),
        fen_lsit = $('#fen_lsit').val(),
        shen_lsit = $('#shen_list').val(),
        /*zong_fin = $('#zong_fin').val(),
        fen_fin = $('#fen_fin').val();*/
        //获取下单账号的memberId
        fen_memberId = $('#sub'+fen_lsit).val(),
        shen_memberId = $('#audit'+shen_lsit).val(),
        zong_memberId = $('#total'+zong_lsit).val();
    $('#fen_lsit')
    var user_data = {
        totalAccount:zong_lsit,
        /*totalLimit:zong_fin,*/
        subAccount:fen_lsit,
        /*subLimit:fen_fin,*/
        auditAccount:shen_lsit,
        relationType:"1",
        contractNum:sessionStorage.getItem("contractNum"),
        /*topLimit:getQueryString('credit'),*/
        customerId:getQueryString('customerId'),
        sub_memberId:fen_lsitid,
        audit_memberId:shen_listid,
        total_memberId:zong_lsitid

    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if (data.errorCode == "0") {
            $.Huimodalalert('已关联', 2000);
            $("#zong_lsit").val("")
            $("#fen_lsit").val("")
            $("#shen_list").val("")
            zhanghao()
        } else {
            $.Huimodalalert(data.errorMessage, 2000)
        }
    }
    return web.doAjax(root.inter.makeRelationship,'post',user_data, succCallBack);
})
function zfsdata (page,current,obj,scrollLoad){
    var user_data = {
        pageNum:1,
        pageSize:10000,
        customerCode:getQueryString('id'),
    }

    var succCallBack = function (data, status, response) {
        if(data.errorCode==0){
            console.log(data.pageBean.totalPage)
            orderList(data);
            $('.M-box3').pagination({
                pageCount: 20,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        type: "POST",
                        url:root.member.findAccountByPage,
                        cache: false,  //禁用缓存
                        dataType: "json",
                        data: {
                            pageNum:api.getCurrent(),
                            pageSize:10000,
                            customerCode:getQueryString('id'),
                        },
                        success: function (result) {
                            if(result.errorCode=="0"){
                                orderList(result);
                            }else {
                                layer.msg(result.errorMessage, {icon: 5,time:1000});
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });
        }
    };
    var dataSource = new Array();
    var table;   //table对象
    dataSource = [];
    function orderList(data) {
        dataSource.splice(0, dataSource.length);//清空数组
        // var datashu =data.list.startIndex+1;
        $.each(data.pageBean.result, function (i, field) {
            // var datashus = datashu++
            var rowData = new Array();
            var power = "";
            rowData.push(field.login_account);
            rowData.push(field.mobile_phone);

            rowData.push("开启");
            // rowData.push(field.member_id);
            rowData.push(field.create_time);
            rowData.push(field.create_user);
            dataSource.push(rowData);
        });
        initDataTable(dataSource);
        console.log(dataSource)
        function initDataTable(dataSource) {
            var dttable = $('#zhcdatatable').dataTable(); // 初始化dataTable，清空上一个值
            dttable.fnClearTable(); //清空一下table
            dttable.fnDestroy(); //还原初始化了的datatable
            $("#zhcdatatable").DataTable({
                "autoWidth": true,
                "ordering": false,
                "searching": true,
                "paging": true,
                "retrieve": false,
                "destroy": false,
                "bAutoWidth": false,
                "bLengthChange": false,
                "aLengthMenu": [10, 5, 25, 50],
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='./loading.gif' />"
                },
                data: dataSource,
                columnDefs: [
                    {
                        "visible": true,
                        "targets": 0
                    },
                ]
            });
        };
    }
    web.doAjax(root.member.findAccountByPage,'post',user_data, succCallBack);

}
zhanghao()
function zhanghao() {
    var user_dataS = {
        contractNum:getQueryString('customerId'),
    }
    var succCallBacks = function (data, status, response) {
        if(data.errorCode=="0"){
            var dataInter=data.data;
            var optionstring = "";
            if(dataInter.length>0){

                $.each(dataInter,function(k,v){
                    var starts=""
                    if(v.account_state==1){
                        starts='<input type="submit" onclick="Close_number('+v.total_sub_audit_account_id+',0,\'确认关闭账号\')" class="btn radius size-MINI c-blue total ml-10 powerButton 243" value="&nbsp;关&nbsp;&nbsp;闭&nbsp;">'
                    }else {
                        starts='<input type="submit" onclick="Close_number('+v.total_sub_audit_account_id+',1,\'确认开启账号\')" class="btn radius size-MINI c-blue total ml-10 powerButton 243" value="&nbsp;开&nbsp;&nbsp;启&nbsp;">'
                    }
                    var auditaccount=""
                    if(v.audit_account==null ){
                        auditaccount="空"
                    }else {
                        auditaccount=v.audit_account
                    }
                    if(v.relation_type==1){
                        optionstring +='<tr>'+
                            '<th>'+v.total_account+' </th>'+
                            '<th>'+v.sub_account+''+starts+' </th>'+
                            '<th>'+auditaccount+' </th>'+
                            '<th>已关联</th>'+
                            '<th><a class="c-red powerButton 243" onclick="Relieve_relationship('+v.total_sub_audit_account_id+',0,\'确认解除关联\')">解除关联</a></th>';

                    }else {
                        optionstring +='<tr>'+
                            '<th>'+v.total_account+' </th>'+
                            '<th>'+v.sub_account+''+starts+' </th>'+
                            '<th>'+auditaccount+' </th>'+
                            '<th>未关联</th>'+
                            '<th><a class="powerButton 243" onclick="Relieve_relationship('+v.total_sub_audit_account_id+',1,\'确认建立关联\')">建立关联</a></th>';
                    }


                })
            }else {
                optionstring+='<th>没有数据</th>'
            }
            $("#guanl_list").html(optionstring);
        }
        power();
    }
    web.doAjax(root.inter.getAccountByContractNum, 'post', user_dataS, succCallBacks);
}
/*var user_dataS = {
    contractNum:getQueryString('customerId'),
}
var succCallBacks = function (data, status, response) {
    console.log(data)
    if(data.errorCode=="0"){
        var dataInter=data.data;
        var optionstring = "";
        if(dataInter.length>0){

        $.each(dataInter,function(k,v){
            var starts=""
            if(v.account_state==1){
                starts='<input type="submit" onclick="Close_number('+v.total_sub_audit_account_id+',0,\'确认关闭账号\')" class="btn radius size-MINI c-blue total ml-10 powerButton 243" value="&nbsp;关&nbsp;&nbsp;闭&nbsp;">'
            }else {
                starts='<input type="submit" onclick="Close_number('+v.total_sub_audit_account_id+',1,\'确认开启账号\')" class="btn radius size-MINI c-blue total ml-10 powerButton 243" value="&nbsp;开&nbsp;&nbsp;启&nbsp;">'
            }
            var auditaccount=""
            if(v.audit_account==null ){
                auditaccount="空"
            }else {
                auditaccount=v.audit_account
            }
            if(v.relation_type==1){
                optionstring +='<tr>'+
                    '<th>'+v.total_account+' </th>'+
                    '<th>'+v.sub_account+''+starts+' </th>'+
                    '<th>'+auditaccount+' </th>'+
                    '<th>已关联</th>'+
                    '<th><a class="c-red powerButton 243" onclick="Relieve_relationship('+v.total_sub_audit_account_id+',0,\'确认解除关联\')">解除关联</a></th>';
            }else {
                optionstring +='<tr>'+
                    '<th>'+v.total_account+' </th>'+
                    '<th>'+v.sub_account+''+starts+' </th>'+
                    '<th>'+auditaccount+' </th>'+
                    '<th>未关联</th>'+
                    '<th><a class="powerButton 243" onclick="Relieve_relationship('+v.total_sub_audit_account_id+',1,\'确认建立关联\')">建立关联</a></th>';
            }

        })
}else {
    optionstring+='<th>没有数据</th>'
}
 $("#guanl_list").html(optionstring);

        /!*var interText = doT.template($("#guanl_bob").text());
        $("#guanl_list").html(interText(dataInter));*!/
    }
}
web.doAjax(root.inter.getAccountByContractNum, 'post', user_dataS, succCallBacks);*/
zfsdata()
// })();
//关闭-开启账号
function Close_number(id,tai,text) {
    var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >'+text+'</span>', {title:'提示',btn: ['确定', '取消']}, function(index){

        var user_data = {
            id:id,
            accountState:tai
        }
            var succCallBack = function (data, status, response) {
                console.log(data)
                if(data.errorCode=="0") {
                    layer.close(curInd);
                    zhanghao()
                }
            };
            return web.doAjax(root.inter.operateRelationship, 'post', user_data, succCallBack);



    },function(){
        layer.close(curInd);

    });



}
//解除建立账号之间的关联关系
function Relieve_relationship(id,tai,text) {


    var curInd = layer.confirm('<span id="status" style="width:200px;height:100px;resize: none;" maxlength="200" >'+text+'</span>', {title:'提示',btn: ['确定', '取消']}, function(index){

        var user_data = {
            id:id,
            relationType:tai
        }

            var succCallBack = function (data, status, response) {
                if(data.errorCode=="0"){
                    layer.close(curInd);
                    zhanghao()
                }else {
                    $.Huimodalalert(data.errorMessage, 2000);
                }
            }
            return web.doAjax(root.inter.relieveRelationship, 'post', user_data, succCallBack);


    },function(){
        layer.close(curInd);

    });


}
function backnow() {
    var user_data = {
        customerId:getQueryString('customerId'),
        customerCode:getQueryString('id'),
        oldSysContractID:getQueryString('oldSysContractID')
    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if(data.errorCode=="0"){
            if(data.errorCode=="0"){
                // layer.msg('返现成功', {icon: 6,time:1000});
            }
        }else {
            // $.Huimodalalert(data.errorMessage, 2000);
        }
    }
    web.doAjax(root.inter.getContractNum, 'post', user_data, succCallBack);
    var user_data_can = {
        customerCode:getQueryString('id')
    }
    var succCallBacks = function (data, status, response) {
        if(data.errorCode=="0"){
            if(data.errorCode=="0"){
                var datatop_co=data.accConInfo
                var interText = doT.template($("#top_lsitdatn_bob").text());
                $("#top_lsitdatn").html(interText(datatop_co));
                sessionStorage.setItem("bel_contract_id",datatop_co.bel_contract_id);
                sessionStorage.setItem("bel_contract_num",datatop_co.bel_contract_num);
            }
        }else {
            // $.Huimodalalert(data.errorMessage, 2000);
        }
    }
    web.doAjax(root.inter.getAccountContractInfoByCustomerCode, 'post', user_data_can, succCallBacks);
}
//商品池配置提交
function Commoditysubmission() {
    var quzhi=JSON.parse(web.readCookie("loginData"))
    var customerCode =getQueryString('id'),
        oldSysContractID =getQueryString('oldSysContractID'),
        syn_cus_oldcontract_id=getQueryString('syn_cus_oldcontract_id'),
        contractEnterDate =getQueryString('contractEnterDate'),
        customerId=getQueryString('customerId')
    var bel_contract_id=sessionStorage.getItem("bel_contract_id"),
        bel_contract_num=sessionStorage.getItem("bel_contract_num");
    var user_data = {
        oldSysContractID:oldSysContractID,
        contractApplyDate:contractEnterDate,
        create_name:quzhi.user.name
    }
    var succCallBack = function (data, status, response) {
        console.log(data)
        if(data.errorCode=="0"){
            if(data.errorCode=="0"){
                layer.msg('提交成功', {icon: 6,time:1000});
                setTimeout( function () {
                    window.location.href="contr_see.html?customerCode="+customerCode+"&oldSysContractID="+oldSysContractID+"&contract_num="+syn_cus_oldcontract_id+'&contract_id='+bel_contract_id+'&xin_contract_num='+bel_contract_num+'&customerId='+customerId+'&id='+customerCode
                },1000);
            }
        }else {
            $.Huimodalalert(data.errorMessage, 2000);
        }
    }
    return web.doAjax(root.inter.commitContractPage, 'post', user_data, succCallBack);
}
//商品池取消
function cancel() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}




